package com.vkserver.server;

import com.vkserver.services.DBManager;
import com.vkserver.services.utils.Answer;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.List;

/**
 *@author roman.prudkogliad@gmail.com
 */
@Path("/answer")
public class AnswerResource {

    @GET
    @Path("/{userId}/{questionId}/{text}")
    @Produces("plain/text")
    public String addAnswer(@PathParam("userId") long userId,
                          @PathParam("questionId") long questionId,
                          @PathParam("text") String text){
        return DBManager.getInstance().addAnswer(new Answer(userId, questionId, text, 0));
    }


    @GET
    @Path("/{questionId}")
    @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    public List<Answer> getAllAnswers(@PathParam("questionId") long questionId){
        return DBManager.getInstance().getAllAnswers(questionId);
    }
}
